<template>
	<view class="content-box">
		<!-- 登录 -->
		<login v-if="!store.isLogin"></login>
		<!-- 游戏 -->
		<game-box ref="gameBoxRef" v-if="store.isLogin" v-show="!fighting" @goFight="goFight"></game-box>
		<!-- 战斗 -->
		<fight v-show="fighting" :fightObj="fightObj" @getResult="getResult"></fight>
		<loadingIndexVue></loadingIndexVue>
	</view>
</template>

<script setup>
	import {
		getShuXing
	} from '../commonMethods/base_index';
	import {
		getHurt
	} from '../commonMethods/fight';
	import {
		probability
	} from '../commonMethods/base';
	import {
		computed,
		onBeforeMount,
		onMounted,
		reactive,
		ref
	} from 'vue';
	import utils from "../common/utils.js"
	import { usePiniaStore } from '../store';
	import gameBox from "./components/gameBox.vue"
	import login from "./components/login.vue"
	import fight from "./components/fight.vue"
	import loadingIndexVue from '../components/loading/loadingIndex.vue';
	
	let store = usePiniaStore()
	let fighting = ref(false)
	let gameBoxRef = ref(null)
	const fightObj = reactive({
		player:{},
		matcher:{}
	})
	
	components:{
		gameBox,login,loadingIndexVue
	}

	onBeforeMount(()=>{
		getBaseShuXing()
		// store.WHOLE_LOADING(true)
		// store.WHOLE_LOADING_PERCENT(50)
		// let num = 50
		// setInterval(()=>{
		// 	num++
		// 	store.WHOLE_LOADING_PERCENT(num)
		// },200)
	})
	onMounted(() => {
	})
	
	const getBaseShuXing = ()=>{
		//首次加载将属性克制放入store
		if(!(store.base_shu_xing&&store.base_shu_xing.length!=0)){
			utils.requestCloudDB("get", {
				collection: "base_shu_xing",
			}, (res) => {
				store.INIT_BASE_SHUXING(res)
			})
		}
	}
	const goFight = (my_jing_ling,other_jing_ling)=>{
		fighting.value = true
		fightObj.player = my_jing_ling
		fightObj.matcher = other_jing_ling
	}
	
	const getResult = (data)=>{
		//  最好进入一下加载动画  
		//这里战斗结束  收尾
		if(data.includes("失败")){
			
		}else if(data.includes("胜利")){
			
		}else if(data.includes("逃")){
			
		}
		gameBoxRef.value.init()
		//提交状态
		fighting.value = false
	}
	
</script>

<style scoped>
	.content-box{
		position: relative;
	}
	
</style>